package speed2010.reformulacao.useful;

import java.io.BufferedReader;
import java.net.HttpURLConnection;
import java.net.URL;
//Gets the user IP
public class IpAddressLookupService {

	private static IpAddressLookupService instance;

	static {
		IpAddressLookupService.instance = new IpAddressLookupService();
	}

	private IpAddressLookupService() {
	}

	public static IpAddressLookupService getInstance() {
		return IpAddressLookupService.instance;
	}

	public String getMyIP() {

		String myIP = "";
		URL url = null;
		HttpURLConnection con = null;
		BufferedReader page = null;

		try {
			url = new URL("http://automation.whatismyip.com/n09230945.asp");
			con = (HttpURLConnection) url.openConnection();
			con.connect();
			page = new java.io.BufferedReader(new java.io.InputStreamReader(con
					.getInputStream()));
			myIP = page.readLine();
			page.close();
			con.disconnect();
		} catch (Exception e) {
			throw new RuntimeException(e);
		}

		return myIP;
	}

}
